﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CommunitySystem.PublicOfficialSelectionService;
using CommunitySystem.ZhaoLuService;

namespace CommunitySystem
{
    public partial class ZhaoLuKaoGuanDetailControl : UserControl
    {
        private PublicOfficialSelectionServiceClient Client = new PublicOfficialSelectionServiceClient();
        private KaoGuanDetailModel model = new KaoGuanDetailModel();
        public ObservableCollection<ZhaoLuJiHuaModel> poi = new ObservableCollection<ZhaoLuJiHuaModel>();
        private ZhaoLuService.ZhaoLuServiceClient Client1 = new ZhaoLuServiceClient();
        public int tiaojian = 0;
        public ZhaoLuKaoGuanDetailControl()
        {
            InitializeComponent();
            Client1.GetZhaoLuJiHuaModelCompleted += new EventHandler<GetZhaoLuJiHuaModelCompletedEventArgs>(Client1_GetZhaoLuJiHuaModelCompleted);
            Client1.GetZhaoLuJiHuaModelAsync(0, "");
        }

        void Client1_GetZhaoLuJiHuaModelCompleted(object sender, GetZhaoLuJiHuaModelCompletedEventArgs e)
        {
            if (e.Result != null)
                poi = e.Result;
            nian.ItemsSource = poi;
            if (poi.Count > 0) nian.SelectedIndex = 0;
            Load();
        }

        public void Load()
        {
            Client.GetKaoGuanDetailModelCompleted += new EventHandler<GetKaoGuanDetailModelCompletedEventArgs>(Client_GetKaoGuanDetailModelCompleted);
            Client.GetKaoGuanDetailModelAsync(name.Text, tiaojian, 0, "招录工作");
        }

        void gangwei_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (((ComboBox)sender).SelectedItem != null)
            {
                tiaojian = ((ZhaoLuJiHuaModel)(((ComboBox)sender).SelectedItem)).ID;
            }
        }

        void Client_GetKaoGuanDetailModelCompleted(object sender, GetKaoGuanDetailModelCompletedEventArgs e)
        {
            DGRole.ItemsSource = null;
            DGRole.ItemsSource = e.Result;
        }

        private void NewData_Click(object sender, RoutedEventArgs e)
        {
            var seljw = this.DGRole.SelectedItem as KaoGuanModel;

            //throw new NotImplementedException();
            if (seljw != null)
            {
                ZhaoLuKaoGuanDetailWindow RMWindow = new ZhaoLuKaoGuanDetailWindow(Convert.ToInt32(seljw.ID));
                RMWindow.Closed += new EventHandler(RMWindow_Closed);
                RMWindow.Show();

            }
            else SilverlightMessageBoxLibrary.Message.ErrorMessage("请选择要编辑的考官信息！");
        }
        void RMWindow_Closed(object sender, EventArgs e)
        {
            Load();
        }

        private void DeleteData_Click(object sender, RoutedEventArgs e)
        {
            var seljw = this.DGRole.SelectedItem as KaoGuanModel;
            if (MessageBox.Show("确定删除吗？", "提示", MessageBoxButton.OKCancel) == MessageBoxResult.OK)
            {
                Client.DeteleKaoGuanDetailModelCompleted -= new EventHandler<DeteleKaoGuanDetailModelCompletedEventArgs>(Client_DeteleKaoGuanDetailModelCompleted);
                Client.DeteleKaoGuanDetailModelCompleted += new EventHandler<DeteleKaoGuanDetailModelCompletedEventArgs>(Client_DeteleKaoGuanDetailModelCompleted);
                Client.DeteleKaoGuanDetailModelAsync(Convert.ToInt32(seljw.ID));
            }
        }

        void Client_DeteleKaoGuanDetailModelCompleted(object sender, DeteleKaoGuanDetailModelCompletedEventArgs e)
        {
            Load();
        }

        private void ChaData_Click(object sender, RoutedEventArgs e)
        {
            Load();
        }
    }
}
